//
//  SecondShotAccountCell.m
//  yameishe3
//
//  Created by pro on 2017/3/13.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "SecondShotAccountCell.h"
#define ImageViewCornerRadius 8
#define btnViewWidth 40
@implementation SecondShotAccountCell{
    
    __weak IBOutlet UILabel *_labelTitle;
    __weak IBOutlet UIImageView *_imageView;
    __weak IBOutlet UILabel *_labelTime;
    __weak IBOutlet UIButton *_btnSelected;
    __weak IBOutlet NSLayoutConstraint *_layoutBtnViewWidth;
    
    UITapGestureRecognizer *_tap;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    UIFont *font = [UIFont fontWithName:@"HelveticaNeue-Light" size:18];
    _labelTitle.font = font;
    _labelTime.font = font;
    _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCell:)];
    [self addGestureRecognizer:_tap];
    _tap.enabled = NO;
    [_btnSelected setImage:[[UIImage imageNamed:@"icon_xuanze_1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateSelected];
    //    _btnSelected.tintColor = AppDayPrimaryColor;
    
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
    
    _imageView.layer.cornerRadius = ImageViewCornerRadius;
    
    _imageView.layer.masksToBounds= YES;

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    [UIView animateWithDuration:0.2 animations:^{
        self.selectedBackgroundView.backgroundColor = selected? [UIColor colorWithWhite:0.97 alpha:1]: [UIColor clearColor];
    }];
}

- (void)setDataSourceWithModel:(NSDictionary *)model isChoose:(BOOL)isChoose isSelected:(BOOL)isSelected isHistory:(BOOL)isHistory {
    
//    _model = model;
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    _layoutBtnViewWidth.constant = isChoose?btnViewWidth:0;
    _tap.enabled = isChoose;
    
    if (!isChoose) {
        //不可多选时重置
        _btnSelected.selected = NO;
    } else {
        _btnSelected.selected = isSelected;
    }
    
    _imageView.backgroundColor = [UIColor colorWithWhite:0.97 alpha:1];
    __weak typeof(UIImageView) *weak_imageViewPic = _imageView;
//    [_imageView setImageWithURL:[NSURL URLWithString:model[@"cover"]] placeholder:[UIImage imageNamed:@"bg_wu.png"] options:YYWebImageOptionSetImageWithFadeAnimation completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
//        weak_imageViewPic.contentMode = (error==nil ? UIViewContentModeScaleAspectFill:UIViewContentModeScaleAspectFit);
//    }];
    
    
    //    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:model.title];
    //    text.lineSpacing = IsiPhone4?3:IsiPhone5?3:IsiPhone6?3:5;
    //    text.font = [UIFont systemFontOfSize:IsiPhone4?16:IsiPhone5?16:IsiPhone6?19:19];
    //    text.color = [UIColor blackColor];
    //    text.lineBreakMode = NSLineBreakByTruncatingTail;
    //    _labelTitle.attributedText = text;
    //    if (IsiPhone4 || IsiPhone5) {
    //        _labelTitle.numberOfLines = 3;
    //    }
    UIFont *font = [UIFont fontWithName:@"HelveticaNeue-Light" size:18];
    _labelTitle.font = font;
    _labelTime.font = font;
//    _labelTitle.text = model.title;
//    _labelTime.text = model.writer;
    //    _labelTime.text = [NSString stringWithFormat:@"%@",[NSString friendTimeWithTimeStr:model.time]];
}
- (IBAction)onTouchSelectedBtn:(UIButton *)sender {
    [self setBtnSelected];
}

- (void)setBtnSelected {
    _btnSelected.selected = !_btnSelected.selected;
    if (_callBackOnTouchSelectBtn) {
        _callBackOnTouchSelectBtn(_btnSelected.selected);
    }
}

- (void)tapCell:(UITapGestureRecognizer *)gesture {
    [self setBtnSelected];
}
@end
